package com.sina.interfaces.web.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sina.interfaces.core.util.JsonUtils;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * Created with IntelliJ IDEA.
 * Description:专用于 json 视图配置  前台
 * 段浩杰   2017-10-23-17:36
 */
@Configuration
public class JsonViewConfig {


    @Bean
    public ObjectMapper jsonViewObjectMapper(@Qualifier("interfaceSessionFactory") SessionFactory sessionFactory) {
        return JsonUtils.createDefaultObjectMapper(sessionFactory);
    }

    @Bean("common/result")
    public View commonResult(@Qualifier("jsonViewObjectMapper") ObjectMapper objectMapper) {
        MappingJackson2JsonView view = new MappingJackson2JsonView(objectMapper);
        view.setExtractValueFromSingleKeyModel(true);
        return view;
    }

   /* @Bean(name = "signature/result")
    public View signatureResult(@Qualifier("jsonViewObjectMapper") ObjectMapper objectMapper){
        SignatureJackson2View view = new SignatureJackson2View();
        view.setObjectMapper(objectMapper);
        view.setExtractValueFromSingleKeyModel(true);
        return view;
    }*/


}
